<?php
namespace App\Service;
use \Illuminate\Support\Facades\Input;
use App\Service\Common;

class Common {

    /**
     * $url         http url  完整url 请求路径   无参数
     * $new_param   http arr  数组
     */
    public static function build_url_query($url, $new_param = [])
    {
        $param = Input::all();
        if (is_array($new_param) ) {
            foreach ($new_param as $at => $val) {
                $param[$at] = $val;
            }
        }

        $url_param = http_build_query($param);
        
        $op = stripos($url, '?') === false ? '?' : '&';
        if ($url_param) {
            $url .= $op . $url_param;
        }
        return $url;
    }

    public static function GetIntTime($time_or_date)
    {
        if (intval($time_or_date).'' != $time_or_date){
            $time_or_date = strtotime($time_or_date);
        }
        
        return intval($time_or_date);
    }
    
    public static function GetSomeDayPeriod($day, $time)
    {
        $day *= -1;
        $str = $day . " days";
        $start = strtotime($str, $time);
        $end = $time;
        return [$start, $end];
    }

    public static function GTF($time, $zero= null)
    {
        if (is_string($time) && intval($time) != $time ){
            return $time;
        }
        $format = 'H:i:s';
        if (!$zero) {
            $format = '00:00:00';
        }
        if ($zero == 24) {
            $format = '23:59:59';
        }
        return date("Y-m-d $format", $time);
    }
}